<template>
  <div class="quality-statistics">
    <el-card>
      <div slot="header" class="card-header">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form :inline="true" :model="queryParams" class="demo-form-inline">
              <el-form-item label="产品">
                <el-select v-model="queryParams.productName" placeholder="请选择产品" clearable @change="handleProductChange">
                  <el-option v-for="item in productOptions" :key="item.id" :label="item.name" :value="item.name"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="批次">
                <el-select v-model="queryParams.batchNo" placeholder="请选择批次" clearable :disabled="!queryParams.productName">
                  <el-option v-for="item in batchOptions" :key="item.id" :label="item.batchNo" :value="item.batchNo"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="工序">
                <el-select v-model="queryParams.processName" placeholder="请选择工序" clearable>
                  <el-option v-for="item in processOptions" :key="item.id" :label="item.name" :value="item.name"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="时间范围">
                <el-date-picker
                  v-model="dateRange"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  @change="handleDateChange">
                </el-date-picker>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="handleQuery">查询</el-button>
                <el-button @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
      </div>
      
      <!-- 统计模块选择 -->
      <el-tabs v-model="activeTab" @tab-click="handleTabClick">
        <el-tab-pane label="合格率统计" name="qualification">
          <qualification-rate-analysis 
            :queryParams="queryParams" 
            :chartData="qualificationData" 
            :loading="loadingQualification" />
        </el-tab-pane>
        <el-tab-pane label="缺陷分析" name="defect">
          <defect-analysis 
            :queryParams="queryParams" 
            :chartData="defectData" 
            :loading="loadingDefect" />
        </el-tab-pane>
        <el-tab-pane label="维修统计" name="repair">
          <repair-statistics 
            :queryParams="queryParams" 
            :chartData="repairData" 
            :loading="loadingRepair" />
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import QualificationRateAnalysis from './quality/QualificationRateAnalysis.vue'
import DefectAnalysis from './quality/DefectAnalysis.vue'
import RepairStatistics from './quality/RepairStatistics.vue'
import { listProduct } from "@/api/qep/product";
import { listProcess } from "@/api/qep/process";
import { listBatch, listBatchByProductName } from "@/api/qep/batch";
import { getQualificationRate, getQualificationTrend, getQualificationCompare,
         getDefectPareto, getDefectDistribution, getDefectTop,
         getRepairRate, getRepairCost, getRepairEvaluation } from "@/api/qep/dataAnalysis";

export default {
  name: "QualityStatistics",
  components: {
    QualificationRateAnalysis,
    DefectAnalysis,
    RepairStatistics
  },
  data() {
    return {
      // 激活的子模块标签
      activeTab: "qualification",
      
      // 产品选项
      productOptions: [],
      // 批次选项
      batchOptions: [],
      // 工序选项
      processOptions: [],
      
      // 日期范围
      dateRange: [],
      
      // 查询参数
      queryParams: {
        productName: null,
        batchNo: null,
        processName: null,
        startDate: null,
        endDate: null
      },
      
      // 合格率统计数据
      qualificationData: {
        summary: {},
        productStats: [],
        batchStats: [],
        processStats: [],
        trend: [],
        compareData: []
      },
      
      // 缺陷分析数据
      defectData: {
        paretoData: [],
        distributionData: {
          locationDistribution: [],
          severityDistribution: [],
          typeDistribution: []
        },
        topDefects: []
      },
      
      // 维修统计数据
      repairData: {
        repairRate: {},
        repairCost: {},
        repairEvaluation: {}
      },
      
      // 加载状态
      loadingQualification: false,
      loadingDefect: false,
      loadingRepair: false
    };
  },
  created() {
    this.getOptions();
    this.initMockData();
    this.handleQuery();
  },
  methods: {
    // 初始化模拟数据
    initMockData() {
      // 模拟产品选项
      this.productOptions = [
        { id: 1, name: '高压管道' },
        { id: 2, name: '焊丝' },
        { id: 3, name: '无缝钢管' },
        { id: 4, name: '法兰阀门' },
        { id: 5, name: '压力容器' }
      ];
      
      // 模拟工序选项
      this.processOptions = [
        { id: 1, name: '原材料检验' },
        { id: 2, name: '焊接工序' },
        { id: 3, name: '机械加工' },
        { id: 4, name: '表面处理' },
        { id: 5, name: '最终检验' }
      ];
      
      // 模拟合格率统计数据
      this.qualificationData = {
        summary: {
          totalCount: 1523,
          qualifiedCount: 1439,
          qualificationRate: 94.5
        },
        productStats: [
          { productName: '高压管道', totalCount: 450, qualifiedCount: 438, qualificationRate: 97.3 },
          { productName: '焊丝', totalCount: 320, qualifiedCount: 304, qualificationRate: 95.0 },
          { productName: '无缝钢管', totalCount: 280, qualifiedCount: 265, qualificationRate: 94.6 },
          { productName: '法兰阀门', totalCount: 273, qualifiedCount: 248, qualificationRate: 90.8 },
          { productName: '压力容器', totalCount: 200, qualifiedCount: 184, qualificationRate: 92.0 }
        ],
        batchStats: [
          { batchNo: 'XY3-01', totalCount: 156, qualifiedCount: 152, qualificationRate: 97.4 },
          { batchNo: '23113940', totalCount: 134, qualifiedCount: 128, qualificationRate: 95.5 },
          { batchNo: '24081823Z', totalCount: 142, qualifiedCount: 135, qualificationRate: 95.1 },
          { batchNo: 'FL-2024-01', totalCount: 128, qualifiedCount: 119, qualificationRate: 93.0 },
          { batchNo: 'PV-2024-03', totalCount: 98, qualifiedCount: 89, qualificationRate: 90.8 }
        ],
        processStats: [
          { processName: '原材料检验', totalCount: 305, qualifiedCount: 299, qualificationRate: 98.0 },
          { processName: '最终检验', totalCount: 298, qualifiedCount: 290, qualificationRate: 97.3 },
          { processName: '焊接工序', totalCount: 285, qualifiedCount: 271, qualificationRate: 95.1 },
          { processName: '机械加工', totalCount: 275, qualifiedCount: 258, qualificationRate: 93.8 },
          { processName: '表面处理', totalCount: 260, qualifiedCount: 241, qualificationRate: 92.7 }
        ],
        trend: [
          { timePoint: '2024-01', qualificationRate: 92.5, totalCount: 125, qualifiedCount: 116 },
          { timePoint: '2024-02', qualificationRate: 93.8, totalCount: 138, qualifiedCount: 129 },
          { timePoint: '2024-03', qualificationRate: 94.2, totalCount: 145, qualifiedCount: 137 },
          { timePoint: '2024-04', qualificationRate: 95.1, totalCount: 152, qualifiedCount: 145 },
          { timePoint: '2024-05', qualificationRate: 94.8, totalCount: 148, qualifiedCount: 140 },
          { timePoint: '2024-06', qualificationRate: 95.5, totalCount: 156, qualifiedCount: 149 },
          { timePoint: '2024-07', qualificationRate: 96.2, totalCount: 162, qualifiedCount: 156 },
          { timePoint: '2024-08', qualificationRate: 94.6, totalCount: 159, qualifiedCount: 150 },
          { timePoint: '2024-09', qualificationRate: 95.8, totalCount: 164, qualifiedCount: 157 },
          { timePoint: '2024-10', qualificationRate: 96.5, totalCount: 168, qualifiedCount: 162 },
          { timePoint: '2024-11', qualificationRate: 95.2, totalCount: 155, qualifiedCount: 148 },
          { timePoint: '2024-12', qualificationRate: 97.1, totalCount: 151, qualifiedCount: 147 }
        ]
      };
      
      // 模拟缺陷分析数据
      this.defectData = {
        paretoData: [
          { defectName: '尺寸超差', count: 45, percentage: 32.1, cumulativePercentage: 32.1 },
          { defectName: '表面缺陷', count: 38, percentage: 27.1, cumulativePercentage: 59.2 },
          { defectName: '焊接气孔', count: 22, percentage: 15.7, cumulativePercentage: 74.9 },
          { defectName: '材质不符', count: 18, percentage: 12.9, cumulativePercentage: 87.8 },
          { defectName: '裂纹缺陷', count: 12, percentage: 8.6, cumulativePercentage: 96.4 },
          { defectName: '其他缺陷', count: 5, percentage: 3.6, cumulativePercentage: 100.0 }
        ],
        distributionData: {
          locationDistribution: [
            { location: '焊缝区域', count: 56, percentage: 40.0 },
            { location: '母材区域', count: 34, percentage: 24.3 },
            { location: '热影响区', count: 28, percentage: 20.0 },
            { location: '接头部位', count: 22, percentage: 15.7 }
          ],
          severityDistribution: [
            { severity: '轻微', count: 78, percentage: 55.7 },
            { severity: '中等', count: 42, percentage: 30.0 },
            { severity: '严重', count: 15, percentage: 10.7 },
            { severity: '极重', count: 5, percentage: 3.6 }
          ],
          typeDistribution: [
            { type: '外观缺陷', count: 68, percentage: 48.6 },
            { type: '尺寸缺陷', count: 45, percentage: 32.1 },
            { type: '焊接缺陷', count: 22, percentage: 15.7 },
            { type: '材质缺陷', count: 5, percentage: 3.6 }
          ]
        },
        topDefects: [
          {
            id: 1,
            defectName: '尺寸超差',
            count: 45,
            trendData: [
              { month: '01月', count: 8 },
              { month: '02月', count: 6 },
              { month: '03月', count: 5 },
              { month: '04月', count: 3 },
              { month: '05月', count: 4 },
              { month: '06月', count: 2 },
              { month: '07月', count: 3 },
              { month: '08月', count: 4 },
              { month: '09月', count: 2 },
              { month: '10月', count: 3 },
              { month: '11月', count: 2 },
              { month: '12月', count: 3 }
            ]
          },
          {
            id: 2,
            defectName: '表面缺陷',
            count: 38,
            trendData: [
              { month: '01月', count: 5 },
              { month: '02月', count: 4 },
              { month: '03月', count: 6 },
              { month: '04月', count: 3 },
              { month: '05月', count: 2 },
              { month: '06月', count: 3 },
              { month: '07月', count: 4 },
              { month: '08月', count: 2 },
              { month: '09月', count: 3 },
              { month: '10月', count: 2 },
              { month: '11月', count: 2 },
              { month: '12月', count: 2 }
            ]
          },
          {
            id: 3,
            defectName: '焊接气孔',
            count: 22,
            trendData: [
              { month: '01月', count: 3 },
              { month: '02月', count: 2 },
              { month: '03月', count: 4 },
              { month: '04月', count: 2 },
              { month: '05月', count: 1 },
              { month: '06月', count: 2 },
              { month: '07月', count: 1 },
              { month: '08月', count: 2 },
              { month: '09月', count: 1 },
              { month: '10月', count: 2 },
              { month: '11月', count: 1 },
              { month: '12月', count: 1 }
            ]
          }
        ]
      };
      
      // 模拟维修统计数据
      this.repairData = {
        repairRate: {
          summary: {
            totalCount: 1523,
            repairCount: 84,
            repairRate: 5.5
          },
          productRepairRates: [
            { productName: '法兰阀门', totalCount: 273, repairCount: 25, repairRate: 9.2 },
            { productName: '压力容器', totalCount: 200, repairCount: 16, repairRate: 8.0 },
            { productName: '无缝钢管', totalCount: 280, repairCount: 15, repairRate: 5.4 },
            { productName: '焊丝', totalCount: 320, repairCount: 16, repairRate: 5.0 },
            { productName: '高压管道', totalCount: 450, repairCount: 12, repairRate: 2.7 }
          ]
        },
        repairCost: {
          summary: {
            totalCost: 156800,
            avgCost: 1866.7,
            materialCost: 89200,
            laborCost: 52400,
            equipmentCost: 15200
          },
          defectTypeCosts: [
            { defectType: '尺寸超差', totalCost: 58200, repairCount: 25, avgCost: 2328 },
            { defectType: '表面缺陷', totalCost: 45600, repairCount: 22, avgCost: 2073 },
            { defectType: '焊接气孔', totalCost: 32800, repairCount: 18, avgCost: 1822 },
            { defectType: '材质不符', totalCost: 15600, repairCount: 12, avgCost: 1300 },
            { defectType: '裂纹缺陷', totalCost: 4600, repairCount: 7, avgCost: 657 }
          ],
          monthlyCosts: [
            { month: '2024-01', totalCost: 12400, repairCount: 8 },
            { month: '2024-02', totalCost: 15200, repairCount: 9 },
            { month: '2024-03', totalCost: 18600, repairCount: 11 },
            { month: '2024-04', totalCost: 14800, repairCount: 7 },
            { month: '2024-05', totalCost: 11200, repairCount: 6 },
            { month: '2024-06', totalCost: 13800, repairCount: 8 },
            { month: '2024-07', totalCost: 16400, repairCount: 9 },
            { month: '2024-08', totalCost: 12600, repairCount: 7 },
            { month: '2024-09', totalCost: 14200, repairCount: 8 },
            { month: '2024-10', totalCost: 13400, repairCount: 6 },
            { month: '2024-11', totalCost: 8600, repairCount: 3 },
            { month: '2024-12', totalCost: 4800, repairCount: 2 }
          ]
        },
        repairEvaluation: {
          summary: {
            totalCount: 84,
            qualifiedCount: 78,
            qualificationRate: 92.9,
            satisfactionScore: 4.3
          },
          qualificationTrend: [
            { month: '2024-01', qualificationRate: 87.5, totalCount: 8, qualifiedCount: 7 },
            { month: '2024-02', qualificationRate: 88.9, totalCount: 9, qualifiedCount: 8 },
            { month: '2024-03', qualificationRate: 90.9, totalCount: 11, qualifiedCount: 10 },
            { month: '2024-04', qualificationRate: 92.9, totalCount: 7, qualifiedCount: 6.5 },
            { month: '2024-05', qualificationRate: 94.2, totalCount: 6, qualifiedCount: 5.65 },
            { month: '2024-06', qualificationRate: 93.8, totalCount: 8, qualifiedCount: 7.5 },
            { month: '2024-07', qualificationRate: 95.6, totalCount: 9, qualifiedCount: 8.6 },
            { month: '2024-08', qualificationRate: 94.3, totalCount: 7, qualifiedCount: 6.6 },
            { month: '2024-09', qualificationRate: 96.3, totalCount: 8, qualifiedCount: 7.7 },
            { month: '2024-10', qualificationRate: 95.0, totalCount: 6, qualifiedCount: 5.7 },
            { month: '2024-11', qualificationRate: 96.7, totalCount: 3, qualifiedCount: 2.9 },
            { month: '2024-12', qualificationRate: 100.0, totalCount: 2, qualifiedCount: 2 }
          ]
        }
      };
    },

    // 获取下拉选项数据
    getOptions() {
      // 获取产品选项
      listProduct().then(response => {
        if (response.code === 200) {
          this.productOptions = response.rows || [];
          console.log('获取到产品列表:', this.productOptions);
        } else {
          console.error('获取产品列表失败:', response.msg);
        }
      }).catch(error => {
        console.error('获取产品列表请求失败:', error);
      });
      
      // 获取工序选项
      listProcess().then(response => {
        if (response.code === 200) {
          this.processOptions = response.rows || [];
          console.log('获取到工序列表:', this.processOptions);
        } else {
          console.error('获取工序列表失败:', response.msg);
        }
      }).catch(error => {
        console.error('获取工序列表请求失败:', error);
      });
    },
    
    // 监听产品选择变化，更新批次选项
    handleProductChange(productName) {
      this.queryParams.batchNo = null;
      this.batchOptions = [];
      
      if (productName) {
        listBatchByProductName(productName).then(response => {
          if (response.code === 200) {
            this.batchOptions = response.data || [];
            console.log('获取到批次列表:', this.batchOptions);
          } else {
            console.error('获取批次列表失败:', response.msg);
          }
        }).catch(error => {
          console.error('获取批次列表请求失败:', error);
        });
      }
    },
    
    // 处理日期选择变化
    handleDateChange(val) {
      if (val) {
        this.queryParams.startDate = val[0];
        this.queryParams.endDate = val[1];
      } else {
        this.queryParams.startDate = null;
        this.queryParams.endDate = null;
      }
    },
    
    // 查询按钮点击
    handleQuery() {
      this.loadData();
    },
    
    // 重置查询
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {
        productName: null,
        batchNo: null,
        processName: null,
        startDate: null,
        endDate: null
      };
      this.handleQuery();
    },
    
    // 标签页切换
    handleTabClick(tab) {
      // 根据切换的标签页加载相应数据
      if (tab.name === "qualification") {
        this.loadQualificationData();
      } else if (tab.name === "defect") {
        this.loadDefectData();
      } else if (tab.name === "repair") {
        this.loadRepairData();
      }
    },
    
    // 加载所有数据
    loadData() {
      this.loadQualificationData();
      if (this.activeTab === "defect") {
        this.loadDefectData();
      } else if (this.activeTab === "repair") {
        this.loadRepairData();
      }
    },
    
    // 加载合格率统计数据
    loadQualificationData() {
      this.loadingQualification = true;
      getQualificationRate(this.queryParams).then(response => {
        this.qualificationData = response.data || {
          summary: {},
          productStats: [],
          batchStats: [],
          processStats: []
        };
        this.loadingQualification = false;
      }).catch(() => {
        this.loadingQualification = false;
      });
    },
    
    // 加载缺陷分析数据
    loadDefectData() {
      this.loadingDefect = true;
      
      // 获取缺陷帕累托数据
      getDefectPareto(this.queryParams).then(response => {
        this.defectData.paretoData = response.data.defectStats || [];
        // 如果没有数据，添加模拟数据
        if (this.defectData.paretoData.length === 0) {
          this.defectData.paretoData = [
            { defectName: '变形', count: 4, percentage: 27, cumulativePercentage: 27 },
            { defectName: '夹渣', count: 4, percentage: 27, cumulativePercentage: 54 },
            { defectName: '未焊透', count: 3, percentage: 20, cumulativePercentage: 74 },
            { defectName: '气孔', count: 2, percentage: 13, cumulativePercentage: 87 },
            { defectName: '裂纹', count: 2, percentage: 13, cumulativePercentage: 100 }
          ];
        }
      }).catch(() => {
        // 添加模拟数据
        this.defectData.paretoData = [
          { defectName: '变形', count: 4, percentage: 27, cumulativePercentage: 27 },
          { defectName: '夹渣', count: 4, percentage: 27, cumulativePercentage: 54 },
          { defectName: '未焊透', count: 3, percentage: 20, cumulativePercentage: 74 },
          { defectName: '气孔', count: 2, percentage: 13, cumulativePercentage: 87 },
          { defectName: '裂纹', count: 2, percentage: 13, cumulativePercentage: 100 }
        ];
      });
      
      // 获取缺陷分布数据
      getDefectDistribution(this.queryParams).then(response => {
        this.defectData.distributionData = response.data || {
          locationDistribution: [],
          severityDistribution: [],
          typeDistribution: []
        };
        
        // 如果没有数据，添加模拟数据
        if (!this.defectData.distributionData.locationDistribution || this.defectData.distributionData.locationDistribution.length === 0) {
          this.defectData.distributionData.locationDistribution = [
            { location: '焊接接头', count: 6 },
            { location: '表面', count: 4 },
            { location: '边缘', count: 3 },
            { location: '内部', count: 2 }
          ];
        }
        
        if (!this.defectData.distributionData.severityDistribution || this.defectData.distributionData.severityDistribution.length === 0) {
          this.defectData.distributionData.severityDistribution = [
            { severity: '轻微', count: 5 },
            { severity: '中等', count: 6 },
            { severity: '严重', count: 3 },
            { severity: '极重', count: 1 }
          ];
        }
        
        if (!this.defectData.distributionData.typeDistribution || this.defectData.distributionData.typeDistribution.length === 0) {
          this.defectData.distributionData.typeDistribution = [
            { type: '尺寸缺陷', count: 7 },
            { type: '表面缺陷', count: 5 },
            { type: '结构缺陷', count: 3 }
          ];
        }
      }).catch(() => {
        // 添加模拟数据
        this.defectData.distributionData = {
          locationDistribution: [
            { location: '焊接接头', count: 6 },
            { location: '表面', count: 4 },
            { location: '边缘', count: 3 },
            { location: '内部', count: 2 }
          ],
          severityDistribution: [
            { severity: '轻微', count: 5 },
            { severity: '中等', count: 6 },
            { severity: '严重', count: 3 },
            { severity: '极重', count: 1 }
          ],
          typeDistribution: [
            { type: '尺寸缺陷', count: 7 },
            { type: '表面缺陷', count: 5 },
            { type: '结构缺陷', count: 3 }
          ]
        };
      });
      
      // 获取TOP缺陷数据
      getDefectTop(this.queryParams).then(response => {
        this.defectData.topDefects = response.data.topDefects || [];
        // 如果没有数据，添加模拟数据
        if (this.defectData.topDefects.length === 0) {
          this.defectData.topDefects = [
            { 
              id: 1, 
              defectName: '变形', 
              count: 4, 
              percentage: 27,
              trendData: [
                { month: '2024-01', count: 2 },
                { month: '2024-02', count: 3 },
                { month: '2024-03', count: 1 },
                { month: '2024-04', count: 4 },
                { month: '2024-05', count: 2 },
                { month: '2024-06', count: 4 }
              ] 
            },
            { 
              id: 2, 
              defectName: '夹渣', 
              count: 4, 
              percentage: 27,
              trendData: [
                { month: '2024-01', count: 1 },
                { month: '2024-02', count: 2 },
                { month: '2024-03', count: 3 },
                { month: '2024-04', count: 4 },
                { month: '2024-05', count: 3 },
                { month: '2024-06', count: 4 }
              ]
            },
            { 
              id: 3, 
              defectName: '未焊透', 
              count: 3, 
              percentage: 20,
              trendData: [
                { month: '2024-01', count: 4 },
                { month: '2024-02', count: 3 },
                { month: '2024-03', count: 2 },
                { month: '2024-04', count: 2 },
                { month: '2024-05', count: 1 },
                { month: '2024-06', count: 3 }
              ]
            }
          ];
        } else {
          // 为每个缺陷添加趋势数据（如果没有）
          this.defectData.topDefects.forEach(defect => {
            if (!defect.trendData || defect.trendData.length === 0) {
              defect.trendData = [
                { month: '2024-01', count: Math.floor(Math.random() * 5) + 1 },
                { month: '2024-02', count: Math.floor(Math.random() * 5) + 1 },
                { month: '2024-03', count: Math.floor(Math.random() * 5) + 1 },
                { month: '2024-04', count: Math.floor(Math.random() * 5) + 1 },
                { month: '2024-05', count: Math.floor(Math.random() * 5) + 1 },
                { month: '2024-06', count: Math.floor(Math.random() * 5) + 1 }
              ];
            }
          });
        }
        this.loadingDefect = false;
      }).catch(() => {
        // 添加模拟数据
        this.defectData.topDefects = [
          { 
            id: 1, 
            defectName: '变形', 
            count: 4, 
            percentage: 27,
            trendData: [
              { month: '2024-01', count: 2 },
              { month: '2024-02', count: 3 },
              { month: '2024-03', count: 1 },
              { month: '2024-04', count: 4 },
              { month: '2024-05', count: 2 },
              { month: '2024-06', count: 4 }
            ] 
          },
          { 
            id: 2, 
            defectName: '夹渣', 
            count: 4, 
            percentage: 27,
            trendData: [
              { month: '2024-01', count: 1 },
              { month: '2024-02', count: 2 },
              { month: '2024-03', count: 3 },
              { month: '2024-04', count: 4 },
              { month: '2024-05', count: 3 },
              { month: '2024-06', count: 4 }
            ]
          },
          { 
            id: 3, 
            defectName: '未焊透', 
            count: 3, 
            percentage: 20,
            trendData: [
              { month: '2024-01', count: 4 },
              { month: '2024-02', count: 3 },
              { month: '2024-03', count: 2 },
              { month: '2024-04', count: 2 },
              { month: '2024-05', count: 1 },
              { month: '2024-06', count: 3 }
            ]
          }
        ];
        this.loadingDefect = false;
      });
    },
    
    // 加载维修统计数据
    loadRepairData() {
      this.loadingRepair = true;
      
      // 获取维修率数据
      getRepairRate(this.queryParams).then(response => {
        this.repairData.repairRate = response.data || {};
      }).catch(() => {
        this.repairData.repairRate = {};
      });
      
      // 获取维修成本数据
      getRepairCost(this.queryParams).then(response => {
        this.repairData.repairCost = response.data || {};
      }).catch(() => {
        this.repairData.repairCost = {};
      });
      
      // 获取维修评估数据
      getRepairEvaluation(this.queryParams).then(response => {
        this.repairData.repairEvaluation = response.data || {};
        this.loadingRepair = false;
      }).catch(() => {
        this.repairData.repairEvaluation = {};
        this.loadingRepair = false;
      });
    }
  },
  watch: {
    'queryParams.productName': {
      handler(val) {
        this.handleProductChange(val);
      }
    }
  }
};
</script>

<style scoped>
.quality-statistics {
  background-color: #fff;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 